package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.Voice;
import com.tanhua.dubbo.api.db.UserInfoApi;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

@Service
public class VoiceApiImpl implements VoiceApi {
    @Reference
    private UserInfoApi userInfoApi;

    @Autowired
    private MongoTemplate mongoTemplate;
    /*
     * 发送语音:
     * 前端参数: soundFile
     * 返回数据: 无
     *
     * */
    @Override
    public void sendVoice(Long userId, String soundUrl) {
        // 构建实体类对象
        Voice voice = new Voice();
        voice.setId(ObjectId.get());// 主键id
        voice.setSoundUrl(soundUrl);// 语音地址
        voice.setCreated(System.currentTimeMillis());//发送语音的时间
        voice.setGender(userInfoApi.findUserInfoById(userId).getGender());// 设置性别
        voice.setUserId(userId);// 设置用户id
        // voice.set_class("com.tanhua.domain.mongo.VoiceMessage");
        // 存储语音地址和其他信息到阿里云以及数据库中
        mongoTemplate.insert(voice);
    }

}
